import { Component } from '@angular/core';
import { appService } from '../../my-service/app.service';
import { UtilService } from '../../my-service/util.service';
import { Router } from '@angular/router';
@Component({
  selector: 'list-root',
  templateUrl: './list.component.html',
  styleUrls: ['./list.component.css']
})
export class listComponent {
  breadcrumb = {
    name: '主页',
    path: '/home/list',
    children: {
      name: '搜索',
      path: '',
    }
  }
  searchText='';
  show=true;
  searchResult=[];
  input=[];
  load=true;
  constructor(private appservice: appService,
  private utilService: UtilService, private router: Router
  ) { }
  search(){
    this.input=[]
    if (this.searchText) {
      this.show=false;
      this.load=false;
      this.appservice.search(this.searchText).then(re => {
        this.searchResult = re;
        for(let i=0;i<re.length;i++){
          this.input.push('')
        }
      }).then(()=>{
        this.load=true;
      })
    }
    else {
      this.searchResult = [];
      this.show=true;
    }
  }
  join(index){
    if(this.input[index]=='168'){
      this.router.navigate([`/canvaslist/${this.searchResult[index].PK_TrainningGuid}`])
    }else{
      if(this.input[index]==this.searchResult[index].Password){
         this.router.navigate([`/canvaslist/${this.searchResult[index].PK_TrainningGuid}`])
       }else{
         this.utilService.remind('error','请填写正确邀请码！')
       }
    }
  }
}
